#!/bin/bash
dirName="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )"
simRootDir="${dirName/scripts/}"

echo -n "Checking AWS cli installed.."

if [[ $(command -v aws) ]]; then
	echo "installed"
else
	echo "not available, check PATH"
	exit 1
fi

echo -n "Checking AWS region defined.."

#if [[ $(aws configure get region) ]]; then
#	echo "defined"
if [[ -n "${AWS_REGION}" ]]; then
	echo "defined"
elif [[ -n "${AWS_DEFAULT_REGION}" ]]; then
	echo "defined"
else
  echo "not defined"
	exit 1
fi

echo -n "Checking Docker is running.."

if [[ $(docker version) ]]; then
	echo "running"
else
	echo "not running"
	exit 1
fi

echo -n "Checking persistent directory exists.."

if [[ -d "${HOME}"/.kubesim ]]; then
	echo "exists"
else
	mkdir -p "${HOME}"/.kubesim
	echo "created"
fi

echo -n "Checking ${simRootDir}terraform/deployments/AWS/.terraform doesn't exist.."

if [[ -d "${simRootDir}"terraform/deployments/AWS/.terraform ]]; then
	rm -R "${simRootDir}"terraform/deployments/AWS/.terraform
	echo "directory deleted"
else
	echo "doesn't exist"
fi
